<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:ui>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>无标题文档</title>
		<link rel="stylesheet" type="text/css" charset="utf-8"
			href="/hrms/css/styles.css" />
		<link rel="stylesheet" type="text/css" charset="utf-8"
			href="/hrms/css/flexigrid.css" />
		<link rel="stylesheet" type="text/css" charset="utf-8"
			href="/hrms/css/flexigrid.pack.css" />
		<link rel="stylesheet" type="text/css" charset="utf-8"
			href="/hrms/css/ztree.css" />

		<script type="text/javascript"
			src="/hrms/js/jquery-1.7.2.min.js"></script>

		<script type="text/javascript"
			src="/hrms/js/jquery.container.js"></script>

		<script type="text/javascript"
			src="/hrms/js/common.js"></script>

		<script type="text/javascript"
			src="/hrms/js/flexigrid.pack.js"></script>

		<script type="text/javascript">
		var setting = {
			check: {
				enable: true,
				chkStyle: "radio",
				radioType: "all"
			},
			view: {
				dblClickExpand: false
			},
			data: {
				simpleData: {
					enable: true,
					idKey: "annalid",
                    pIdKey: "parent.annalid",
                    rootPId: "null",
				},
            key:{
                name:"orgname"
                }
			},
			callback: {
				onClick: onClick,
				onCheck: onCheck
			}
		};
		
		var setting_update = {
			check: {
				enable: true,
				chkStyle: "radio",
				radioType: "all"
			},
			view: {
				dblClickExpand: false
			},
			data: {
                simpleData: {
                    enable: true,
                    idKey: "annalid",
                    pIdKey: "parent.annalid",
                    rootPId: "null",
                },
            key:{
                name:"orgname"
                }
            },
			callback: {
				onClick: u_onClick,
				onCheck: u_onCheck
			}
		};
 
		function onClick(e, treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("treeDemo");
			zTree.checkNode(treeNode, !treeNode.checked, null, true);
			return false;
		}
 
		function onCheck(e, treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
			nodes = zTree.getCheckedNodes(true),
			orgname = "",orgid="";
			
			for (var i=0, l=nodes.length; i<l; i++) {
				orgid += nodes[i].annalid + ",";
				orgname+=nodes[i].orgname+",";
			}
			if (orgname.length > 0 ) orgname = orgname.substring(0, orgname.length-1);
			var form_orgname = $("#parentname");
			form_orgname.attr("value",orgname);
			
			if(orgid.length>0)orgid=orgid.substring(0,orgid.length-1);
			var form_orgid=$("#parentid");
			form_orgid.attr("value",orgid);
		}
		
		function u_onClick(e, treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("u_treeDemo");
			zTree.checkNode(treeNode, !treeNode.checked, null, true);
			return false;
		}
 
		function u_onCheck(e, treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("u_treeDemo"),
			nodes = zTree.getCheckedNodes(true),
			orgname = "",orgid="";
			
			for (var i=0, l=nodes.length; i<l; i++) {
				orgid += nodes[i].annalid + ",";
				orgname+=nodes[i].orgname+",";
			}
			if (orgname.length > 0 ) orgname = orgname.substring(0, orgname.length-1);
			var form_orgname = $("#u_parentname");
			form_orgname.attr("value",orgname);
			
			if(orgid.length>0)orgid=orgid.substring(0,orgid.length-1);
			var form_orgid=$("#u_parentid");
			form_orgid.attr("value",orgid);
		}
 
		function showMenu() {
			var cityObj = $("#parentname");
			var cityOffset = $("#parentnam").offset();
			$("#menuContent").slideDown("fast");
 
			$("body").bind("mousedown", onBodyDown);
		}
		
		function hideMenu() {
			$("#menuContent").fadeOut("fast");
			$("body").unbind("mousedown", onBodyDown);
		}
		function onBodyDown(event) {
			if (!(event.target.id == "menuBtn" || event.target.id == "parent" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)) {
				hideMenu();
			}
		}
		function u_showMenu() {
			var cityObj = $("#u_parent");
			var cityOffset = $("#u_parent").offset();
			$("#u_menuContent").slideDown("fast");
 
			$("body").bind("mousedown", onBodyDown_update);
		}
		
		function u_hideMenu() {
			$("#u_menuContent").fadeOut("fast");
			$("body").unbind("mousedown", onBodyDown_update);
		}
		function u_onBodyDown(event) {
			if (!(event.target.id == "menuBtn" || event.target.id == "u_parentid" || event.target.id == "u_menuContent" || $(event.target).parents("#u_menuContent").length>0)) {
				u_hideMenu();
			}
		}
	$(document).ready( function() {
		//表单验证插件启动
		$("#fm_add").validationEngine();
		$("#fm_update").validationEngine();
	    //外部查询
	    $("#orgmgr_query").click(function(){
	        var orgcode=$("#orgcode").val();
	        var orgname=$("#orgname").val();
	        var params={extParam:[{name:"orgcode",value:orgcode},{name:"orgname",value:orgname}]};
	        $("#querylist").flexOptions(params).flexReload();
	    });
		
		demand("orgmgr");
		$("#bn_add").click(function(){
		    $("#fm_add").ajaxSubmit({
		    	success:function(data){
		    		$("#dept_add").dialog("close");
		    		alert("组织机构添加成功！");
					$("#querylist").flexReload();
		    	},
		    	error:function(){
		    		alert("组织机构添加失败！");
		    	}
		    });
		});
		$("#bn_update").click(function(){
			$("#fm_update").ajaxSubmit({
				success:function(data){
					$("#dept_update").dialog("close");
					alert("组织机构修改成功！");
					$("#querylist").flexReload();
				},
				error:function(e){
					alert("组织机构修改失败!");
				}
			});
			
		});
		$("#dept_update").dialog("close");
		$("#dept_add").dialog("close");
	});
</script>

	</head>

	<body onload="loadDemand('orgmgr')">
		<div align="center">
			<br />
			<br />
			<br />
			
			<table width="80%" border="0" class="table_frame" align="center">

				<thead class="table_title">
					<tr><td align="center">
						机构信息管理
					</td></tr>
				</thead>
				<tr>
					<td>
					    <form id="fr_query"  action="" >
						<table width="100%" border="0" class="table_block">
							<tr>
								<td align="right">
									机构编号：
								</td>
								<td align="left">
									<input id="orgcode" name="orgcode" type="text" size="20" />
									&nbsp;
								</td>
								<td align="right">
									机构名称：
								</td>
								<td align="left">
									<input id="orgname" name="orgname" type="text" size="20" />
								</td>
							</tr>
							<tr>
								<td colspan="4" align="center">
									<input id="orgmgr_query" name="query" type="button" value="查询" class="button_image" />
									<input name="reset" type="reset" class="button_image" />
								</td>

							</tr>
						</table>
						</form>
					</td>
				</tr>
				<tr>
					<td height="20"></td>
				</tr>
				<tr>
					<td>
						<div>
							<table id="querylist"></table>
							<script type="text/javascript">
	$("#querylist").flexigrid( {
		url :'/hrms/webservice/resources/org/queryByPage',
		dataType :'json',
		colModel : [ {
			display :'机构编号',
			name :'orgcode',
			width :160,
			sortable :true,
			align :'center'
		}, {
			display :'机构名称',
			name :'orgname',
			width :180,
			sortable :true,
			align :'left'
		}, {
			display :'父级机构',
			name :'parentid',
			width :120,
			sortable :true,
			align :'left',
			hide:true
		}, {
			display :'父级机构',
			name :'parentname',
			width :180,
			sortable :true,
			align :'left'
		}, {
			display :'机构别名',
			name :'briefname',
			width :130,
			sortable :true,
			align :'left'
		}, {
			display :'部门类型',
			name :'type',
			width :80,
			sortable :true,
			align :'right',
			hide:true
		}, {
			display :'部门类型',
			name :'typeStr',
			width :80,
			sortable :true,
			align :'right'
		}  , {
			display :'创建日期',
			name :'createdateStr',
			width :180,
			sortable :true,
			align :'right'
		} ],
		buttons : [ {
			name :'新增机构',
			bclass :'add',
			onpress :add
		}, {
			name :'机构编辑',
			bclass :'edit',
			onpress :update
		}, {
			name :'机构调整',
			bclass :'adjust',
			onpress :adjust
		}
		, {
			name :'删除机构',
			bclass :'delete',
			onpress :remove
		}, {
			separator :true
		} ],
		searchitems : [ {
			display :'机构编号',
			name :'orgcode'
		}, {
			display :'机构名称',
			name :'orgname',
			isdefault :true
		} ],
		sortname :"orgcode",
		sortorder :"asc",
		usepager :true,
		title :'机构信息列表',
		useRp :true,
		rp :15,
		showTableToggleBtn :true,
		width :1000,
		height :200
	});
	function add(com, grid) {
		//初始化参照
		$.ajax({url:appPath+"webservice/resources/org/queryByRefer",
	               success:function(data){
	                   if(data!=null&&data!="undefined"&&data!=""){
	                       $.fn.zTree.init($("#treeDemo"), setting, data);
	                   }
	               }
	    });
		$("#dept_add").dialog("open");
		$.ajax({url:"/hrms/webservice/resources/keyGen/genKey?tablecode=RBAC_ORGINFO&custom=",
		dataType:"json",
		sucess:function(data){
		},error:function(XMLHttpRequest, textStatus, errorThrown){
		    $("#a_orgcode").attr("value",XMLHttpRequest.responseText);
		}});
	}
	function update(com, grid) {
		//获得选中的记录
		var selected_length=$(".trSelected",grid).length;
		if(selected_length<1){
			alert("请选择一条需要编辑的组织机构后，再点击组织机构编辑按钮！");
			return false;
		}
		if(selected_length>1){
			alert("编辑组织机构只能选择一条记录进行处理，请重新选择！");
			return false;
		}
		//获得机构编号
		var orgcode=$(".trSelected td:nth-child(1) div",grid).text();
		$.ajax({
			url:"/hrms/webservice/resources/org/getOrgDetail?orgcode="+orgcode,
			success:function(_data){
				$("body").DataLink({
					data : _data,
					formId :"fm_update"
				});
			},
			error:function(){
				alert("获取组织机构详细信息时出现异常！");
			}
		});
		//初始化参照
		$.ajax({url:appPath+"webservice/resources/org/queryByRefer",
            success:function(data){
                if(data!=null&&data!="undefined"&&data!=""){
                    $.fn.zTree.init($("#u_treeDemo"), setting, data);
                }
            }
 		});
		$("#dept_update").dialog("open");
	}
	function remove(com, grid) {
		//获得选中的记录
		var selected_length=$(".trSelected",grid).length;
		if(selected_length<1){
			alert("请选择一条需要删除的组织机构后，再点击组织机构删除按钮！");
			return false;
		}
		var iscon=confirm('确认要删除选中的组织机构吗？');
		if(iscon){
		var codes="";
		$(".trSelected td:nth-child(1) div",grid).each(function(index){
			if(index)
				codes+=",";
			codes+=$(this).text();
		});
		$.ajax({
			url:"/hrms/webservice/resources/org/delete?orgcodes="+codes,
			success:function(data){
				alert("删除组织机构成功！");
				$("#querylist").flexReload();
			},
			error:function(){
				alert("删除组织机构失败！");
			}
		});
		}
	}
	function adjust(com,grid){
		alert("请选择需要调整的部门后，在进行部门调整操作！");
	}
</script>
						</div>
					</td>
				</tr>
			</table>
			<div align="center">
				<br />
				<br />
				<table width="90%" border="0" class="table_frame" align="center">
					<tr>
						<td align="center">
							<input id="demand" name="" type="button" value="需求收集"
								class="button_image" />
						</td>
					</tr>
					<tr>
						<td align="center">
							<div id="demand_input" style="display: none">
								<textarea rows="15" cols="120" id="demand_text"></textarea>
								<br />
								<input id="demand_save" type="button" class="button_image"
									value="保存需求" />
							</div>
						</td>
					</tr>
				</table>
				<table id="demand_des" width="90%" border="0" class="table_frame"
					align="center">
					<thead align="center" class="table_title">
					<tr><td>
							需求描述
						</td></tr>
					</thead>
				</table>
			</div>
		</div>
		<ui:dialog id="dept_add" title="机构新增" height="270" width="700"
			modal="true" autoOpen=false>
			<form id="fm_add"
				action="/hrms/webservice/resources/org/addOrg"
				method="post">
				<table class="table_frame" width="100%">
					<tr>
						<td align="right">
							机构编号:
						</td>
						<td align="left">
							<input type="text" id="a_orgcode" name="orgcode"	class="validate[required] text-input" maxlength="128"></input>
							<font color="red">*</font>
						</td>
						<td align="right">
							上级机构:
						</td>
						<td align="left">
							<input id="parentname" name="parentname" type="text" readonly="readonly" value=""
								size="20" onclick="showMenu();" />
							<input id="parentid" name="parent.annalidStr" type="hidden" />
							<div id="menuContent" class="menuContent"
								style="display: none; position: absolute;">
								<ul id="treeDemo" class="ztree"
									style="margin-top: 0; width: 180px; height: 100px;"></ul>
							</div>
							<font color="red">*</font>
						</td>
					</tr>
					<tr>
						<td align="right">
							机构名称:
						</td>
						<td align="left">
							<input type="text" id="a_orgname" name="orgname"
								class="validate[required] text-input" maxlength="128"></input>
							<font color="red">*</font>
						</td>
						<td align="right">
							机构别名:
						</td>
						<td align="left">
							<input type="text" id="briefname" name="briefname"
								maxlength="128"></input>
						</td>
					</tr>
					<tr>
						<td align="right">
							机构类型:
						</td>
						<td align="left">
							<select id="type" name="type">
							     <option value="1">
							         基本组织
							      </option>
							      <option value="0">
							          非一般性组织
							      </option>
							</select>
						</td>
						<td align="right">
							机构状态:
						</td>
						<td align="left">
							<select id="valid" name="valid">
								<option value="1">
									正常
								</option>
								<option value="0">
									注销
								</option>
							</select>
						</td>
					</tr>
					<tr>
						<td align="right">
							机构备注:
						</td>
						<td align="left" colspan="3">
							<textarea cols="50" rows="4" id="a_remark" name="remark"></textarea>
						</td>
					</tr>
					<tr>
						<td align="right" colspan="2">
							<input type="button" value="保存" class="button_image" id="bn_add" />
						</td>
						<td align="left" colspan="2">
							<input type="reset" value="重置" class="button_image" />
						</td>
					</tr>
				</table>
			</form>
		</ui:dialog>
		<ui:dialog id="dept_update" title="机构信息编辑" height="270" width="700"
			modal=true  autoOpen=false>
			<form id="fm_update"
				action="/hrms/webservice/resources/org/update"
				method="post">
				<input type="hidden" name="annalidStr" id="annalidStr"/>
				<input type="hidden" name="createdateStr"/>
				<table class="table_frame" width="100%">
					<tr>
						<td align="right">
							机构编号:
						</td>
						<td align="left">
							<input type="text" id="orgcode" name="orgcode"
								class="validate[required] text-input" maxlength="128"></input>
							<font color="red">*</font>
						</td>
						<td align="right">
							上级机构:
						</td>
						<td align="left">
							<input id="u_parentname" name="parent.orgname" type="text" readonly="readonly" value=""
								size="20" onclick="u_showMenu();" />
							<input id="u_parentid" name="parent.annalidStr" type="hidden" />
							<div id="u_menuContent" class="menuContent"
								style="display: none; position: absolute;">
								<ul id="u_treeDemo" class="ztree"
									style="margin-top: 0; width: 180px; height: 100px;"></ul>
							</div>
							<font color="red">*</font>
						</td>
					</tr>
					<tr>
						<td align="right">
							机构名称:
						</td>
						<td align="left">
							<input type="text" id="orgname" name="orgname"
								class="validate[required] text-input" maxlength="128"></input>
							<font color="red">*</font>
						</td>
						<td align="right">
							机构别名:
						</td>
						<td align="left">
							<input type="text" id="briefname" name="briefname"
								maxlength="128"></input>
						</td>
					</tr>
					<tr>
						<td align="right">
							机构类型:
						</td>
						<td align="left">
							<select id="type" name="type">
							     <option value="1">
							         基本组织
							      </option>
							      <option value="0">
							          非一般性组织
							      </option>
							</select>
						</td>
						<td align="right">
							机构状态:
						</td>
						<td align="left">
							<select id="state" name="state">
								<option value="1">
									正常
								</option>
								<option value="0">
									注销
								</option>
							</select>
						</td>
					</tr>
					<tr>
						<td align="right">
							机构备注:
						</td>
						<td align="left" colspan="3">
							<textarea cols="50" rows="4" id="remark" name="remark"></textarea>
						</td>
					</tr>
					<tr>
						<td align="right" colspan="2">
							<input type="button" value="保存" class="button_image" id="bn_update" />
						</td>
						<td align="left" colspan="2">
							<input type="reset" value="重置" class="button_image" />
						</td>
					</tr>
				</table>
			</form>
		</ui:dialog>
	</body>
</html>
